<?php
/* 
   ## 中文化: http://fall-leaf.net / 2009-01-06
   Recent Guestbook plugin for Textcube 1.6
   ----------------------------------
   Version 1.6
   Tatter Network Foundation development team / Needlworks

   Creator          : Peris
   Maintainer       : Peris, inureyes, graphittie
   Editor			: J.Parker

   Created at       : 2006.7.25
   Last modified at : 2008.02.25

 This plugin shows recent eeplies on 'quilt'.
 For the detail, visit http://forum.Textcube.com/ko


 General Public License
 http://www.gnu.org/licenses/gpl.html

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

*/
// lib/model/comment.php : 367 line
function _getRecentGuestbook($blogid) {
	global $skinSetting, $database, $configVal, $pluginURL;
	requireComponent('Textcube.Function.misc');
	$data = misc::fetchConfigVal($configVal);
	$authorized = doesHaveOwnership();
	$comments = array();
	$repliesChk = ($data['repliesChk'] == 1)?"":" AND replier is NULL ";
	$limitLine = ($data['repliesList'])?$data['repliesList']:$skinSetting['commentsOnRecent'];
	$sql = "SELECT * FROM {$database['prefix']}Comments WHERE blogid = {$blogid} AND entry=0 AND isFiltered = 0 {$repliesChk} ORDER BY written DESC LIMIT {$limitLine}";
	if ($result = mysql_query($sql)) {
		while ($comment = mysql_fetch_array($result)) {
			if (($comment['secret'] == 1) && !$authorized) {
				$comment['name'] = _text('비밀방문자');
				$comment['comment'] = _text('관리자만 볼 수 있는 방명록입니다.');
			}else{$comment['replier'] = "";}
			$comment['secret'] = "";
			array_push($comments, $comment);
		}
	}
	return $comments;
}

// lib/view/view.php : 906 line
function _getRecentGuestbookView($comments, $template) {
	requireComponent("Eolin.PHP.Core");
	requireComponent("Textcube.Function.misc");
	global $blogURL, $skinSetting, $configVal;
	$data = misc::fetchConfigVal($configVal);
	ob_start();
	foreach ($comments as $comment) {
		$view = "$template";
		$recentGuestbookLength = ($data['recentGuestbookLength'])?$data['recentGuestbookLength']:30;
		misc::dress('rctrp_rep_link', "$blogURL/guestbook/{$comment['id']}#guestbook{$comment['id']}", $view);
		misc::dress('rctrp_rep_desc', htmlspecialchars(UTF8::lessenAsEm($comment['comment'], $recentGuestbookLength)), $view);
		misc::dress('rctrp_rep_time', fireEvent('ViewRecentCommentDate', Timestamp::format2($comment['written'])), $view);
		misc::dress('rctrp_rep_name', htmlspecialchars(UTF8::lessenAsEm($comment['name'],10)).$comment['secret'].$comment['replier'], $view);
		print $view;
	}
	$view = ob_get_contents();
	ob_end_clean();
	return $view;
}

// lib/piece/blog/end.php : 48 line
function RecentRG_Default($target) {
	global $blogid, $configVal;	
	$data = misc::fetchConfigVal($configVal);
	$data['guestbookheader']	= isset($data['guestbookheader'])?$data['guestbookheader']:"<div class=\"listbox\">\n<h3>Recent Guestbooks</h3>".CRLF;
	$data['guestbookfooter']	= isset($data['guestbookfooter'])?$data['guestbookfooter']:"</div>".CRLF;
	$target = $data['guestbookheader'].CRLF;
	$target .='<ul>'.CRLF;
	$target .= _getRecentGuestbookView(_getRecentGuestbook($blogid),'<li><a href="[##_rctrp_rep_link_##]">[##_rctrp_rep_desc_##].</a> <span class="name">[##_rctrp_rep_name_##]</span> <span class="date">[##_rctrp_rep_time_##]</span></li>'.CRLF);
	$target .='</ul>'.CRLF;
	$target .= $data['guestbookfooter'].CRLF;
	return $target;
}

function RecentRG_Default_DataSet($DATA){
	requireComponent('Textcube.Function.misc');
	$cfg = misc::fetchConfigVal($DATA);
	return true;
}
?>
